package com.mall.service.marketing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.common.CommonPage;
import com.mall.model.domain.SmsCouponHistory;
import com.mall.service.marketing.mapper.CouponHistoryMapper;
import com.mall.service.marketing.service.CouponHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName CouponHistoryServiceImpl
 * @Description
 * @Author Young
 * @Date 2023/3/11 20:08
 * @Version 1.0
 */
@Service
public class CouponHistoryServiceImpl implements CouponHistoryService {

    @Autowired
    private CouponHistoryMapper couponHistoryMapper;

    /**
     * 根据优惠券id，使用状态，订单编号分页获取领取记录
     * @param smsCouponHistory
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public CommonPage findCouponHistory(SmsCouponHistory smsCouponHistory, Integer pageNum, Integer pageSize) {
        Long couponId = smsCouponHistory.getCouponId();
        String orderSn = smsCouponHistory.getOrderSn();
        Integer useStatus = smsCouponHistory.getUseStatus();//
        //创建分页对象
        IPage<SmsCouponHistory> iPage = new Page<>(pageNum,pageSize);
        //创建条件表达式
        LambdaQueryWrapper<SmsCouponHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SmsCouponHistory::getCouponId,couponId)
                .eq(SmsCouponHistory::getOrderSn,orderSn)
                .eq(SmsCouponHistory::getUseStatus,useStatus);
        couponHistoryMapper.selectPage(iPage,queryWrapper);
        CommonPage page = CommonPage.getPage((Page) iPage);
        return page;
    }
}
